//
//  ZPMineZhuanbanVC.m
//  ZPIOSEducation
//
//  Created by 李伟 on 2017/1/15.
//  Copyright © 2017年 mini1. All rights reserved.
//

#import "ZPMineZhuanbanVC.h"
#import "ZPSelectClassVC.h"
#import "ZPSelectedZhuanClassCell.h"
#import "ZPSelectCurriculumCell.h"

static NSString  * const reuseIdentifier_tablecell      = @"ZPSelectedZhuanClassCell";
static NSString  * const reuseIdentifier_collectioncell = @"ZPSelectCurriculumCell";
@interface ZPMineZhuanbanVC ()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{
  
}
@property (weak, nonatomic) IBOutlet UITableView *zhuanbanTabV;
@property (weak, nonatomic) IBOutlet UIButton *nextStep;
@property (strong, nonatomic) UICollectionView *collectionView;
@property (strong, nonatomic) UICollectionViewFlowLayout *layout;
@property (strong, nonatomic) ZPSelectedZhuanClassCell *tableCell;
@property (strong, nonatomic) ZPSelectCurriculumCell *collectionCell;
@property (copy, nonatomic) NSArray *numbers;
@end

@implementation ZPMineZhuanbanVC
- (ZPSelectedZhuanClassCell *)tableCell;
{
    if (_tableCell == nil) {
        _tableCell= [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPSelectedZhuanClassCell class]) owner:self options:nil] lastObject];
        self.collectionView = [[UICollectionView alloc] initWithFrame:_tableCell.calendarView.bounds collectionViewLayout:self.layout];
        self.collectionView.backgroundColor = zColor(84, 185, 240);
        [self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ZPSelectCurriculumCell class]) bundle:nil] forCellWithReuseIdentifier:reuseIdentifier_collectioncell];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [_tableCell.calendarView addSubview:self.collectionView];

    }
    return _tableCell
    ;
}

- (ZPSelectCurriculumCell *)collectionCell
{
    if (_collectionCell == nil) {
        _collectionCell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([ZPSelectCurriculumCell class]) owner:self options:nil] lastObject];
    }
    return _collectionCell;
}


- (UICollectionViewFlowLayout *)layout { //CollectionView布局
    if (_layout == nil) {
        _layout = [[UICollectionViewFlowLayout alloc] init];
    }
    return _layout;
}

//- (UICollectionView *)collectionView
//{
//    if (_collectionView == nil) {
//        _collectionView = [[UICollectionView alloc] initWithFrame:self.tableCell.calendarView.bounds collectionViewLayout:self.layout];
//        _collectionView.backgroundColor = zColor(84, 185, 240);
//        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ZPSelectCurriculumCell class]) bundle:nil] forCellWithReuseIdentifier:reuseIdentifier_collectioncell];
//    }
//    return _collectionView;
//}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.view addSubview:hud];
    self.zhuanbanTabV.delegate = self;
    self.zhuanbanTabV.dataSource = self;
    
    self.numbers = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12"];
    [self getintoclasslist];
}

-(void)getintoclasslist{
    [hud showAnimated:YES];
    [[ZPNetworking sharedZPNetworking] GET:APIUC@"adjust/getintoclasslist.json" parameters:@{@"stuId":[[[ZPAuthStore sharedZPAuthStore] userToDic] objectForKey:@"stuId"],@"classId":_classId,@"teacherId":_teacherId,@"teachId":_teachId} progress:nil success:^(id  _Nonnull responseObject) {
        [hud hideAnimated:YES];
        if (CodeIs200(responseObject)) {
            NSDictionary *result = [responseObject objectForKey:@"result"];
            
        }else{
            [ZPPromptView showMessage:toStr([responseObject objectForKey:@"codeMsg"])];
        }
    } failure:^(NSError * _Nonnull error) {
        [ZPPromptView showMessage:error.localizedDescription];
        [hud hideAnimated:YES];
    }];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.title = @"转班";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zhenpin_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClick)];
}
- (void)backButtonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.tableCell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_tablecell];
    self.tableCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return self.tableCell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 8.;
}


#pragma mark - <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { //单元个数
    return 12;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.collectionCell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier_collectioncell forIndexPath:indexPath];
    self.collectionCell.numberLab.text = self.numbers[indexPath.row];
    return self.collectionCell;
}

// 返回collectionView里的某个组里item最小行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

//  返回collectionView里的某个组里item最小列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

// 返回collectionView里的某个section的item大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.tableCell.calendarView.xj_width/6, self.tableCell.calendarView.xj_height/2);
}


- (IBAction)nextStepClick:(id)sender
{
    ZPSelectClassVC * vc = [[ZPSelectClassVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
